/* @(#)B.11.31_LR $Revision: ../hdr/iconv.h@@/main/i80/CHECKEDOUT $ */
/* Header for iconv(3C) */

#ifndef _ICONV_INCLUDED /* allow multiple inclusions */
#define _ICONV_INCLUDED

#ifndef _SYS_STDSYMS_INCLUDED
#  include <sys/stdsyms.h>
#endif /* _SYS_STDSYMS_INCLUDED */

#ifndef _SYS_TYPES_INCLUDED
#	include <sys/types.h>   /** To get size_t **/
#endif

#ifdef __cplusplus
   extern "C" {
#endif

#ifdef _INCLUDE_HPUX_SOURCE

#ifndef __LP64__
#include <dl.h>
#endif /* __LP64__ */
#include <wchar.h>

#define	ICONV_VERSION	1
#define	ICONV_MAGIC	0xA5E1
#define	WHAT_LEN	80
#define	IS_1BYTE	0x8000		/* is_1byte flag */
#define	MAX_CHAR	MB_LEN_MAX	/* should be MB_LEN_MAX */


/*
 * WARNING: the iconv tables are shared by both the 32-bit and
 *	the 64-bit iconv() in libc.  Structures and data types
 *	used to create the iconv tables must be the same size
 *	in ILP32 and LP64.
 */

typedef struct {
	wint_t    from;
	wint_t    to;
} ConvArr;

typedef struct {
    uint32_t		version;		/* Version number */
    unsigned short	magic;			/* Magic number */
    char		whatstr[WHAT_LEN];	/* String output using "what" */
} _iconv_hdr;

typedef struct	__iconv_rec	*iconv_t, iconv_rec;

struct	__iconv_rec {
	_iconv_hdr	hdr;
	int	(*init) __((iconv_t cd));
	size_t	(*exec) __((iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft));
	int	(*close) __((iconv_t cd));
	int	(*mblen) __((const char *s, size_t len));
#ifndef __LP64__
	shl_t	meth_handle, loc_handle;/* shl_load handles saved here */
#else
	void	*meth_handle, *loc_handle; /* dlopen handles saved here */
#endif /* !__LP64__ */
	ConvArr	*Tptr;			/* pointer to table data */
	size_t  tab_size;		/* table size in bytes */
	wint_t	Galley;			/* The Galley Chars */

	/* this following structure is for flags and global data */
	union {
		void 	*dptr;	/* pointer may refer to any global data */
		uint32_t flag;	/* for flags */
		uint32_t state;	/* for state variable */
	} xtend;
};

typedef struct {
	_iconv_hdr	hdr;
	uint32_t	arr_size;	/* size of table in BYTES */
	int32_t		is_1byte;	/* flag denoting 1 byte table */
	wint_t		Galley;		/* The Galley Chars */
} _iconvTabHdr;


#else /* ! _INCLUDE_HPUX_SOURCE */

typedef void *iconv_t;

#endif /* _INCLUDE_HPUX_SOURCE */

#if defined(__ia64)
  /* pragmas needed to support -B protected */  
#  pragma extern iconv_open, iconv, iconv_close
#endif /* __ia64 */ 


extern iconv_t	iconv_open __((const char *, const char *));
extern size_t	iconv __((iconv_t, char ** __restrict, size_t * __restrict, char ** __restrict, size_t * __restrict));
extern int	iconv_close __((iconv_t));

#ifdef __cplusplus
   }
#endif

#endif /* _ICONV_INCLUDED */

